/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  cn.hutool.core.util.ObjectUtil
 *  de.felixroske.jfxsupport.FXMLController
 *  javafx.event.EventHandler
 *  javafx.fxml.FXML
 *  javafx.fxml.Initializable
 *  javafx.scene.control.Button
 *  javafx.scene.input.KeyCode
 *  javafx.scene.input.KeyEvent
 *  javafx.scene.layout.Pane
 *  javafx.stage.Stage
 *  javafx.stage.WindowEvent
 *  org.springframework.beans.factory.annotation.Autowired
 */
package com.gys.controller.salesReceipts;

import cn.hutool.core.util.ObjectUtil;
import com.gys.GysApplication;
import com.gys.common.util.CacheUtil;
import com.gys.common.util.SpringUtil;
import com.gys.controller.BaseController;
import com.gys.controller.LoginController;
import com.gys.controller.dataManger.ControllerManger;
import com.gys.controller.index.IndexController;
import com.gys.controller.salesReceipts.SalesReceiptsMainController;
import com.gys.view.LoginView;
import com.gys.view.salesReceipts.ChangeDutyTipView;
import de.felixroske.jfxsupport.FXMLController;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.Timer;
import java.util.TimerTask;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import org.springframework.beans.factory.annotation.Autowired;

@FXMLController
public class ChangeDutyTipController
extends BaseController
implements Initializable {
    @FXML
    private Button sureBtn;
    @FXML
    private Pane changeDutyTipPane;
    @Autowired
    private SalesReceiptsMainController salesReceiptsMainController;
    @Autowired
    private LoginController loginController;

    public void initialize(URL location, ResourceBundle resources) {
        ControllerManger.controllerMap.put(this.getClass().getSimpleName(), this);
        new Timer().schedule(new TimerTask(){

            @Override
            public void run() {
                ChangeDutyTipView view = SpringUtil.getBean(ChangeDutyTipView.class);
                Stage stage = (Stage)view.getView().getScene().getWindow();
                stage.setOnCloseRequest((EventHandler)new EventHandler<WindowEvent>(){

                    public void handle(WindowEvent event) {
                        CacheUtil.put("isChangeDutyTipCurrentView", false);
                        CacheUtil.put("needChange", 1);
                        ChangeDutyTipController.this.salesReceiptsMainController.changDutyTip();
                    }
                });
            }
        }, 1000L);
        this.init();
    }

    @Override
    public void init() {
        if (ObjectUtil.isEmpty(this.changeDutyTipPane)) {
            return;
        }
        this.sureBtn.requestFocus();
        new Timer().schedule(new TimerTask(){

            @Override
            public void run() {
                ChangeDutyTipView view = SpringUtil.getBean(ChangeDutyTipView.class);
                Stage stage = (Stage)view.getView().getScene().getWindow();
                stage.getScene().setOnKeyReleased((EventHandler)new EventHandler<KeyEvent>(){

                    public void handle(KeyEvent e) {
                        if (e.getCode() == KeyCode.ENTER) {
                            ChangeDutyTipController.this.sureAction();
                        } else if (e.getCode() == KeyCode.ESCAPE) {
                            ChangeDutyTipController.this.cancelAction();
                        }
                        e.consume();
                    }
                });
            }
        }, 200L);
        CacheUtil.put("isChangeDutyTipCurrentView", true);
    }

    @FXML
    public void sureAction() {
        this.cancelAction();
        CacheUtil.put("needChange", 2);
        CacheUtil.put("isChangeDutyTipCurrentView", false);
        IndexController.stage.close();
        CacheUtil.getCacheManager().getCache("sysCache").flush();
        this.loginController.init();
        GysApplication.showView(LoginView.class);
    }

    @FXML
    void cancelAction() {
        CacheUtil.put("isChangeDutyTipCurrentView", false);
        CacheUtil.put("needChange", 1);
        this.salesReceiptsMainController.changDutyTip();
        this.changeDutyTipPane.getScene().getWindow().hide();
    }
}

